package com.xiechuang.util.url;

import lombok.extern.slf4j.Slf4j;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;

/**
 * @Description: url工具类
 * @Author xiechuang
 * @Date 2022/8/30
 */
@Slf4j
public class UrlUtil {

    private static final String CHARSET = "UTF-8";

    public static String encode(String content) {
        String encodeResult = null;
        try {
            encodeResult = URLEncoder.encode(content, CHARSET);
        } catch (UnsupportedEncodingException e) {
            log.error("encode error", e);
        }
        return encodeResult;
    }

    public static String decode(String content) {
        String decodeResult = null;
        try {
            decodeResult = URLDecoder.decode(content, CHARSET);
        } catch (UnsupportedEncodingException e) {
            log.error("decode error", e);
        }
        return decodeResult;
    }

}
